commonlibsse_ng\re\h/
hkQuaternion.rs

1use crate::re::hkVector4::hkVector4;
2
3/// Represents a quaternion in the Havok system.
4///
5/// This struct wraps a single `hkVector4` where the components typically represent
6/// (x, y, z, w) with w being the real part and (x, y, z) the imaginary vector part.
7///
8/// # Memory Layout:
9/// - `vec`: The quaternion as a 4D vector (0x00 - 0x0F)
10#[repr(C)]
11#[derive(Debug, Clone, Copy)]
12pub struct hkQuaternion {
13    /// The 4D vector storing the quaternion components (x, y, z, w).
14    /// - Offset: 0x00
15    pub vec: hkVector4,
16}
17
18// Compile-time memory layout verification
19const _: () = {
20    assert!(core::mem::offset_of!(hkQuaternion, vec) == 0x0);
21    assert!(core::mem::size_of::<hkQuaternion>() == 0x10);
22};
23
24impl hkQuaternion {
25    /// Creates a new `hkQuaternion` with all components set to zero (invalid quaternion).
26    #[inline]
27    pub fn new() -> Self {
28        Self { vec: hkVector4::new() }
29    }
30
31    /// Creates a new identity quaternion (w = 1, x = y = z = 0).
32    #[inline]
33    pub fn identity() -> Self {
34        Self { vec: hkVector4::from_components(0.0, 0.0, 0.0, 1.0) }
35    }
36}
37
38impl Default for hkQuaternion {
39    #[inline]
40    fn default() -> Self {
41        Self::identity() // Default to identity quaternion, which is more useful than all zeros
42    }
43}